package com.unhz.generator.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by cxg on 2017/7/4 0004.
 *
 * @Author 曹显贵
 * @Date 2017/7/4 0004 21:09
 */
public class DateHelper {
    //将时间类型转换成字符串
    public static String ContentDate(Date dateString){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String startTime = sdf.format(dateString);
        return startTime;
    }
    public static String ContentFZDate(Date dateString){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String startTime = sdf.format(dateString);
        return startTime;
    }
    public static String ContentNowDate(Date dateString){
        SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddhhmmssSSS");
        String startTime = sdf.format(dateString);
        return startTime;
    }
    //计算时间差(分钟)
    public static int ContentTimeCha(String createTime,String nowTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            long from = sdf.parse(createTime).getTime();
            long to = sdf.parse(nowTime).getTime();
            return (int) ((to - from)/(1000 * 60));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
    //计算时间差(天数)
    public static int ContentTimeDate(String createTime,String nowTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            long from = sdf.parse(createTime).getTime();
            long to = sdf.parse(nowTime).getTime();
            return (int)((to - from)/(1000 * 60 * 60 * 24));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }


}
